#include "Main.h"
#include "SubtitlePlayer.h"
#ifdef _DEBUG
    #include <iostream>
    using std::wcout;
    using std::endl;
#endif
using namespace SubtitlePlayerSpace;
SubtitlePlayer sp;

DLL_EXPORT int InitSubs(const LPCWSTR path, const LPCWSTR encoding)
{
    int initializationStatus = 0;

    sp = SubtitlePlayer(path, encoding, initializationStatus);
    return initializationStatus;
}

DLL_EXPORT LPCWSTR GetError()
{
    return SubtitlePlayer::GetLastErrorMessage();
}

DLL_EXPORT LPCWSTR SupportedType()
{
    return L"srt";
}

DLL_EXPORT long GetEndTime()
{
    return sp.GetEndTime();
}

DLL_EXPORT int GetFirstSubSize()
{
    return sp.GetFirstSubSize();
}

DLL_EXPORT errno_t GetFirstSub(long* endTime, LPWSTR sub, size_t maxStringSize)
{
    wstring firstSub = sp.GetFirstSub(*endTime);
    return wcsncpy_s(sub, maxStringSize, firstSub.c_str(), _TRUNCATE);
}

DLL_EXPORT LPCWSTR GetNextSub(long * duration)
{
    return sp.GetNextSub(*duration).c_str();
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}